# 封装类
import requests


class EmpManageApi(object):
    # 添加员工
    def add_emp(self, req_head, req_body):
        resp = requests.post(url="http://ihrm2-test.itheima.net/api/sys/user/",
                             headers=req_head, json=req_body)
        return resp

    # 查询员工
    def query_emp(self, emp_id, req_head):
        resp = requests.get(url="http://ihrm2-test.itheima.net/api/sys/user/" + emp_id,
                            headers=req_head)
        return resp

    # 修改员工
    def modify_emp(self, emp_id, req_head, req_body):
        resp = requests.put(url=f"http://ihrm2-test.itheima.net/api/sys/user/{emp_id}",
                            headers=req_head, json=req_body)
        return resp

    # 删除员工
    def del_emp(self, emp_id, req_head):
        resp = requests.delete(url="http://ihrm2-test.itheima.net/api/sys/user/" + emp_id,
                               headers=req_head)
        return resp


if __name__ == '__main__':
    # 添加员工
    # emp = EmpManageApi()
    # req_head = {"Content-Type": "application/json",
    #             "Authorization": "06991562-4045-4d86-84e2-38b9007b3982"}
    # req_body = {
    #     "username": "jack123",
    #     "mobile": "13040460782",
    #     "workNumber": "666"
    # }
    # resp = emp.add_emp(req_head,req_body)
    # print(resp.json())

    # 查询员工
    emp = EmpManageApi()
    emp_id = "1570682285496217600"
    req_head = {"Authorization": "99bdea6c-762a-4b3f-aebd-21a1724cafeb"}
    resp = emp.query_emp(emp_id, req_head)
    print(resp.json())


    # 修改员工
    # emp_id = "1570682285496217600"
    # req_body = {"username": "lisa123"}
    # resp = emp.modify_emp(emp_id, req_head, req_body)
    # print(resp.json())

    # 删除员工
    # emp_id = "1570682285496217600"
    # req_head = {"Authorization": "06991562-4045-4d86-84e2-38b9007b3982"}
    # resp = emp.del_emp(emp_id, req_head)
    # print(resp.json())


